<template>
    <div class="box">
        <div class="pic">
            <img :src="item.imgUrl" alt="">
        </div>
        <div class="info">
            <div class="title">{{ item.name }}</div>
            <div class="wrapper">
                <div class="num">
                    月售{{ item.saleNum }} 好评率{{item.goodRate*100}}%
                </div>
                <div class="tag">
                    <i class="iconfont icon-tag"></i>
                    <span>{{ item.discount }}折 限{{item.limitNum}}份</span>
                </div>
                <view class="price">
                    <div class="left">
                        <span class="normal">¥{{ item.newPrice }}</span>
                        <span class="through">¥{{ item.oldPrice }}</span>
                    </div>
                    <div class="right">
                        <!-- <div class="btn" @click="showGuige" v-if="false">
                            选规格
                        </div> -->
                        <template v-if="item.num">
                            <div class="mius" @click="minus(item)">-</div>
                            <div class="num">{{ item.num }}</div>
                            <div class="add" @click="buyGoods(item)">+</div>
                        </template>
                        <div class="add" v-else @click="buyGoods(item)">+</div>
                    </div>
                </view>
            </div>
        </div>
        <modal :open="open" @hide="hidden"></modal>
    </div>
</template>

<script setup>
import { useCartStore } from '@/store/module/cart';
import modal from './modal.vue';
import { ref } from 'vue';

const cartStore = useCartStore()

let open = ref(false)

defineProps({
    item:{
        type:Object,
        default(){
            return {}
        }
    }
})

const showGuige = () => {
    open.value = true
    // console.log(111)
}

const hidden = ()=>{
    open.value=false
}

const buyGoods= (goods)=>{
    cartStore.buy(goods)
}

const minus=(goods) => {
    cartStore.minus(goods)
}
</script>

<style scoped lang="scss">
.box {
    display: flex;
    padding: 10px;

    .pic{
        width: 100px;
        height: 100px;
        border-radius: 3px;
        overflow: hidden;

        img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
    }

    .info {
        padding: 0 15px 0 8px;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .title {
            font-size: 15px;
            color: #333;
            padding: 0;
        }

        .wrapper {
            .num {
                font-size: 11px;
                color: #999;
                margin: 10px 0;
            }

            .tag {
                margin: 10px 0;
                font-size: 11px;
                color: #F63747;

                .iconfont {
                    font-size: 11px;
                }
            }

            .price {
                display: flex;
                justify-content: space-between;
                align-items: center;

                .left {
                    .normal {
                        color: #F63747;
                        font-size: 15px;
                    }

                    .through {
                        text-decoration: line-through;
                        font-size: 11px;
                        color: #999;
                    }
                }

                .btn {
                    width: 50px;
                    height: 22px;
                    font-size: 12px;
                    background: #2493F1;
                    color: #fff;
                    border-radius: 22px;
                    line-height: 22px;
                    text-align: center;
                }

                .right {
                    display: flex;
                    justify-content: space-around;
                    align-items: center;
                    color: #000;
                    bottom: 28px;
                    left: 0;

                    .mius {
                        width: 24px;
                        height: 24px;
                        border-radius: 50%;
                        border: 1px solid #2493F1;
                        color: #2493F1;
                        box-sizing: border-box;
                        text-align: center;
                        line-height: 24px;
                        font-size: 13px;
                    }

                    .num{
                        margin: 0 10px;
                    }

                    .add {
                        font-size: 13px;
                        width: 24px;
                        height: 24px;
                        text-align: center;
                        line-height: 24px;
                        background: #2493F1;
                        border-radius: 50%;
                        color: #fff;
                    }
                }
            }
        }
    }
}
</style>